package com.niit.gjl.firmhousenum;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;



public class FirmHouseNumMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    private Text outk = new Text();
    private IntWritable outv = new IntWritable(1);

    /**
     * map阶段核心的业务逻辑（读取一行数据 进行切割 将切割后的每一个公司打标记1 然后输出）
     *
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        if (key.get() == 0) // 跳过标题行
            return;

        // 获取当前行数据
        String lineData = value.toString();
        String[] datas = lineData.split("\t");
        // 遍历datas给每一个打标记 输出
        if (datas.length >= 16) {
            outk.set(datas[15]);
            context.write(outk, outv);
        }
    }
}
